package com.impetus.project.skilltest.common;

public class SkillTestException extends Exception{
	private static final long serialVersionUID = 7670788615058571658L;
	private char NEW_LINE = '\n';
	
	private int exceptionCode;
	
	public SkillTestException(){
		super();
	}
	public SkillTestException(String msg){
		super(msg);
	}
	public SkillTestException(String msg, int exceptionCode){
		super(msg);
		this.exceptionCode = exceptionCode;
	}
	
	public SkillTestException(String msg, Throwable t){
		super(msg, t);
	}
	public SkillTestException(String msg, Throwable t, int exceptionCode){
		super(msg, t);
		this.exceptionCode = exceptionCode;
	}
	
	public SkillTestException(Throwable t){
		super(t);
	}
	public SkillTestException(Throwable t, int exceptionCode){
		super(t);
		this.exceptionCode = exceptionCode;
	}
	
	public String getStackTraceAsString(){
		final StringBuilder result = new StringBuilder();
		if(exceptionCode != 0){
			result.append("Exception Code ["+exceptionCode+"]");
		}
		result.append(toString());
		result.append(NEW_LINE);
		//add each element of the stack trace
	    for (StackTraceElement element : getStackTrace() ){
	      result.append( element );
	      result.append( NEW_LINE );
	    }
	    return result.toString();
	}
}
